﻿SmitearWebGL.Core.Math.BitFlags = Class.extend(
{
	/******** constructor ********/
	
	init : function( value )
	{
		/******** private property ********/
		
		this._value = value || 0;
		
		this._registClass( "SmitearWebGL.Core.Math.BitFlags" );
	}
	,
	
	/******** public method ********/
	
	set : function( value )
	{
		this._value = value;
	}
	,
	clear : function()
	{
		this._value = 0;
	}
	,
	setFlags : function( value )
	{
		this._value |= value;
		this._value >>>= 0;
	}
	,
	setFlagsByFlags : function( flags )
	{
		this._value |= flags._value;
		this._value >>>= 0;
	}
	,
	clearFlags : function( value )
	{
		this._value &= ~ value;
		this._value >>>= 0;
	}
	,
	clearBit : function( bit )
	{
		this._value &= ( ~ ( 1 << bit ) );
		this._value >>>= 0;
	}
	,
	setBit : function( bit, setting )
	{
		if ( setting == undefined || setting == true )
		{
			this._value |= ( 1 << bit );
			this._value >>>= 0;
		}
		else
		{
			this.clearBit( bit );
		}
	}
	,
	isEmpty : function()
	{
		return( this._value == 0 );
	}
	,
	testBit : function( bit )
	{
		return ( ( this._value & ( 1 << bit ) ) > 0 )
	}
	,
	testFlags : function( test )
	{
		return( ( this._value & test ) == test );
	}
	,
	testAny : function( test )
	{
		if ( this._value > 0 && test > 0 )
		return true;
		else
		return false;
	}
	,
	contain : function( bit )
	{
		return ( ( this._value & bit ) > 0 );
	}
	,
	highestBit : function()
	{
		return SmitearWebGL.Core.Math.highestBitSet( this._value );
	}
	,
	lowestBit : function()
	{
		return SmitearWebGL.Core.Math.lowestBitSet( this._value );
	}
}
);